package com.kakavr.split.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.kakavr.base.controller.BaseController;
import com.kakavr.result.MsgResult;
import com.kakavr.statistics.service.IStatisticsService;
import com.kakavr.util.SessionUtils;

@RestController
@RequestMapping("statistics")
public class StatisticsController extends BaseController {
	@Resource
	private IStatisticsService statisticsService;
	
	/**
	 * 销售报表
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "sale", method = RequestMethod.GET)
	public Map<String, Object> sale(HttpServletRequest request){
		String type = request.getParameter("type");
		String begin = request.getParameter("begin");
		String end = request.getParameter("end");
		String storeId = request.getParameter("storeId");
		Map<String, Object> map = this.initPaginationParams(request);
		if (StringUtils.isNotBlank(begin)) {
			map.put("begin", begin);
		}
		if (StringUtils.isNotBlank(end)) {
			map.put("end", end);
		}
		if (StringUtils.isNotBlank(storeId)) {
			map.put("storeId", storeId);
		}
		map.put("partnerId", SessionUtils.getPartnerId());
		map.put("type", type);
		return MsgResult.okResultData(statisticsService.statisSale(map));
	}

}
